import { useContext, useMemo } from 'react';
import ConfigProvider from '../../config-provider';
import useProps from '../../hooks/use-props';
import { unitToPx } from '../../utils/format';
import { PickerBaseProps } from '../interface';

interface BaseProps {
	optionHeight: number;
	visibleOptionsCount: number;
	transitionDuration: number;
}

function usePickerProps<T extends PickerBaseProps>(
	props: T,
): [BaseProps, Pick<T, Exclude<keyof T, keyof BaseProps>>] {
	const configContext = useContext(ConfigProvider.Context);

	const optionHeight = useMemo<number>(
		() => unitToPx(props.optionHeight || 44),
		[props.optionHeight],
	);

	return useProps<BaseProps, T>(
		{
			optionHeight,
			visibleOptionsCount: 6,
			transitionDuration: configContext.transitionDuration,
		},
		props,
	);
}

export default usePickerProps;
